<template>
  <zh-form-card title="基本信息" :span="24">
    <zh-form ref="formRef" :model="data.formData" label-width="200px" :span="12" :rules="data.rules">
            <zh-form-input
          prop="aac001"
          label="个人编号"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aac001"
      ></zh-form-input>
      <zh-form-input
          prop="aac002"
          label="社会保障号"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aac002"
      ></zh-form-input>
      <zh-form-input
          prop="aab001"
          label="单位编号"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aab001"
      ></zh-form-input>
      <zh-form-input
          prop="bab010"
          label="统一社会信用代码"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.bab010"
      ></zh-form-input>
      <zh-form-input
          prop="aab004"
          label="单位名称"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aab004"
      ></zh-form-input>
      <zh-form-input
          prop="baz159"
          label="参保关系id"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.baz159"
      ></zh-form-input>
      <zh-form-input
          prop="aac003"
          label="姓名"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aac003"
      ></zh-form-input>
      <zh-form-input
          prop="aac147"
          label="证件号码"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aac147"
      ></zh-form-input>
      <zh-form-input
          prop="aac058"
          label="证件类型"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aac058"
      ></zh-form-input>
      <zh-form-input
          prop="aae140"
          label="险种"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aae140"
      ></zh-form-input>
      <zh-form-input
          prop="aac008"
          label="参保状态"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aac008"
      ></zh-form-input>
      <zh-form-input
          prop="aac031"
          label="个人缴费状态"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aac031"
      ></zh-form-input>
      <zh-form-input
          prop="aae030"
          label="开始日期"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aae030"
      ></zh-form-input>
      <zh-form-input
          prop="aae031"
          label="终止日期"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aae031"
      ></zh-form-input>
      <zh-form-input
          prop="dscCity"
          label="所属地市"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.dscCity"
      ></zh-form-input>
      <zh-form-input
          prop="aab301"
          label="行政区划代码"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.aab301"
      ></zh-form-input>
      <zh-form-input
          prop="year"
          label="年份"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.year"
      ></zh-form-input>
      <zh-form-input
          prop="sourceType"
          label="数据来源：1 大数据获取 2管理员录入 3 学校录入"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.sourceType"
      ></zh-form-input>
      <zh-form-input
          prop="continuityFlag"
          label="是否连续缴纳"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.continuityFlag"
      ></zh-form-input>
      <zh-form-input
          prop="total"
          label="累计缴费月数"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.total"
      ></zh-form-input>
      <zh-form-input
          prop="totalBc"
          label="当前参保单位累计缴费月数"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.totalBc"
      ></zh-form-input>
      <zh-form-input
          prop="totalBclx"
          label="当前参保单位连续缴费月数"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.totalBclx"
      ></zh-form-input>
      <zh-form-input
          prop="totalFlag"
          label="是否获取累计缴费月数 0 未获取 1获取成功 2获取失败"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.totalFlag"
      ></zh-form-input>
      <zh-form-date
          prop="totalTime"
          label="最新累计缴费月数获取时间"
          type="datetime"
          :disabled="props.disabled"
          v-model="data.formData.totalTime"
          :span="8"
      ></zh-form-date>
      <zh-form-input
          prop="totalRemarks"
          label="累计缴费月数获取备注"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.totalRemarks"
      ></zh-form-input>
      <zh-form-input
          prop="totalErrorCnt"
          label="累计缴费月数获取失败次数"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.totalErrorCnt"
      ></zh-form-input>
      <zh-form-input
          prop="materials"
          label="佐证材料"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.materials"
      ></zh-form-input>
      <zh-form-input
          prop="continuityMsg"
          label="是否连续缴纳获取异常情况"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.continuityMsg"
      ></zh-form-input>
      <zh-form-input
          prop="authStatus"
          label="审核状态"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.authStatus"
      ></zh-form-input>
    </zh-form>
  </zh-form-card>
</template>

<script lang="ts" setup name="eduSocialSecurityOfflineForm">
import { ElMessage } from 'element-plus';

//------------------定义子组件---------------------------
const formRef = ref();
//------------------接收传入参数(组件)-------------------
const props = defineProps({
  socialSecurityId: {
    type: String,
    default: '',
  },
  disabled: {
    type: Boolean,
    default: true,
  },
  btnLoding: Boolean,
});
const emits = defineEmits(['update:btnLoding', 'canner', 'refreshTable']);
//------------------初始化------------------------------
onMounted(() => {
  getDict();
  getsurveyInfo();
});
//------------------内部变量定义-------------------------
const data = reactive({
  formData: {} as any,
  detailVisible: true,
  loading: false,
  rules: {
  },
  dictData: {} as any,
  areaCodeDict: [] as any,
  campusParam: {} as any,
});

// 查询数据字典信息
const getDict = () => {
  const params = {} as any;
  params.dictFields = '';
  $api.common.getBatchDict.post(params).then((res) => {
    data.dictData = res.result;
  });
};

//获取详情
const getsurveyInfo = () => {
  if (!props.socialSecurityId) {
    return;
  }
  data.loading = true;
  $api.common.send
  .post('eduSocialSecurityOffline0002', { socialSecurityId: props.socialSecurityId })
  .then((res: any) => {
    data.formData = res.result || {};
    data.loading = false;
    data.campusParam.schoolId = data.formData.schoolId;
  })
  .catch(() => {
    data.loading = false;
  });
};

//保存
async function saveBase() {
  let checkFlag = await formRef.value.checkForm();
  if (checkFlag) {
    if (data.formData.socialSecurityId) {
      $api.common.send
      .post('eduSocialSecurityOffline0005', data.formData)
      .then(() => {
        ElMessage.success('修改成功');
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = false));
        emits('refreshTable');
      })
      .catch(() => {
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = true));
      });
    } else {
      $api.common.send
      .post('eduSocialSecurityOffline0004', data.formData)
      .then(() => {
        ElMessage.success('新增成功');
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = false));
        emits('refreshTable');
      })
      .catch(() => {
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = true));
      });
    }
  }
}

//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({ saveBase });
</script>
<style lang="scss" scoped></style>
